<?php
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class ShenHeController extends AdminBaseController
{    
    public function index()
    {
        $uid=cmf_get_current_admin_id();
        $uinfo=get_operator_data($uid);
        $storeId = $this->request->param('storeid');
        
        if(isset($storeId) && !empty($storeId)){
            $con['storeid'] = $storeId;
            $map['id']=$storeId;
        }else{
            //获取自己管辖的所有店铺
            $userList=get_user_list($uid);
            $uid_list_str=toStr($userList,'userid');
            $uid_list_str.=','.$uid;
            $store_id_list=get_store_list($uid_list_str);
            
            if($store_id_list){
                $con['storeid']=array('in',$store_id_list);
                $map['id']=array('in',$store_id_list);
            }else{
                $con['storeid']=array('in','');
                $map['id']=array('in','');
            }
        }
        $map['status']=1;
        $con['g_status']=-1;
        $list_store_list=DB::name('store')->where($map)->select()->toarray();
        $data['id']=0;
        $data['store_name']='全部';
        $type=array();
        if(!$storeId){
            $type['0']=$data;
        }
        foreach($list_store_list as $k=>$v)
        {
            $k=$k+1;
            $type[$k]=$v;
        }
        $goods_list=Db::name('Goods')->where($con)->paginate(10);
        $goods_list->appends(['storeid'=>$storeId]);
        $page = $goods_list->render();
        //$list_store_list=Db::name('Store')->where($map)->select()->toarray();//正在运营的店铺列表
        $this->assign("page", $page);
        $this->assign("list_store_list", $type);
        $this->assign("list", $goods_list);
       // $this->assign('list_store_list',$type);
        return $this->fetch();
    }
    public function agree(){
        $id=$this->request->param('g_id');
        $check=Db::name('Goods')->where(array('g_id'=>$id))->find();
        if($check){
            $re=Db::name('Goods')->where(array('g_id'=>$id))->update(['g_utime' =>time(), 'g_status' => 1]);
            if($re){
                $this->success('操作成功');
            }else{
                $this->error('操作失败');
            }
        }else{
            $this->error('此商品不存在');
        }
    }
    public function refuse(){
        $id=$this->request->param('g_id');
        $check=Db::name('Goods')->where(array('g_id'=>$id))->find();
        if($check){
            $re=Db::name('Goods')->where(array('g_id'=>$id))->update(['g_utime' =>time(), 'g_status' => -2]);
            if($re){
                $this->success('操作成功');
            }else{
                $this->error('操作失败');
            }
        }else{
            $this->error('此商品不存在');
        }
    }
}
